package doc2db.interfaces.elements;


import doc2db.Keey;
import doc2db.Launcher;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.AbstractAction;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;

/**
 *
 * @author yura
 */
public class AboutJava extends JDialog {
    private JButton closeButton = new JButton(new AbstractAction("close") {
            @Override public void actionPerformed(ActionEvent arg0) {
                closeAboutJava();
            }
        });
    private JLabel appTitleLabel = new JLabel();
    private JLabel versionLabel = new JLabel();
    private JLabel appVersionLabel = new JLabel();
    private JLabel vendorLabel = new JLabel();
    private JLabel appVendorLabel = new JLabel();
    private JLabel homepageLabel = new JLabel();
    private JLabel appHomepageLabel = new JLabel();
    private JLabel appDescLabel = new JLabel();
    private JLabel imageLabel = new JLabel();

    public AboutJava(java.awt.Frame parent) {
        super(parent);
        initComponents();
        position();
        getRootPane().setDefaultButton(closeButton);
    }

    //@Action
    public void closeAboutJava() {
        dispose();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     */
    private void initComponents() {

        String java_vendor = System.getProperty("java.vendor");  //Sun Microsystems Inc.
        final String java_url = System.getProperty("java.vendor.url"); //http://java.sun.com/
        String java_version = System.getProperty("java.version");//1.6.0_15
        String java_vm_name = System.getProperty("java.vm.name");//Java HotSpot(TM) Client VM
        
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(Launcher.getString("aboutjava.title"));
        setModal(true);
        setName("aboutJava");
        setResizable(false);

        //closeButton.setAction(actionMap.get("closeAboutJava"));
        closeButton.setName("closeButton"); 

        appTitleLabel.setFont(appTitleLabel.getFont().deriveFont(appTitleLabel.getFont().getStyle()
                | java.awt.Font.BOLD, appTitleLabel.getFont().getSize()+4));
        appTitleLabel.setText(java_vm_name);

        versionLabel.setFont(versionLabel.getFont().deriveFont(versionLabel.getFont().getStyle()
                | java.awt.Font.BOLD));
        versionLabel.setText(Launcher.getString("versionLabel.text"));
        versionLabel.setName("versionLabel"); 

        appVersionLabel.setText(java_version);

        vendorLabel.setFont(vendorLabel.getFont().deriveFont(vendorLabel.getFont().getStyle()
                | java.awt.Font.BOLD));
        vendorLabel.setText(Launcher.getString("vendorLabel.text"));
        vendorLabel.setName("vendorLabel"); 

        appVendorLabel.setText(java_vendor);

        homepageLabel.setFont(homepageLabel.getFont().deriveFont(homepageLabel.getFont().getStyle()
                | java.awt.Font.BOLD));
        homepageLabel.setText(Launcher.getString("homepageLabel.text"));
        homepageLabel.setName("homepageLabel"); 

        appHomepageLabel.setText("<html><i color=blue><u>" + java_url);

        appDescLabel.setText(Launcher.getString("aboutjava.appDescLabel.text"));
        appDescLabel.setName("appDescLabel"); 

        imageLabel.setIcon(Launcher.getIcon("aboutjava.imageLabel.icon"));
        imageLabel.setName("imageLabel"); 

        appHomepageLabel.addMouseListener(new MouseAdapter() {
            @Override public void mouseClicked(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1)
                    Keey.openBrowser(java_url);
            }
        });
        appHomepageLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
        appHomepageLabel.setToolTipText(homepageLabel.getText() + java_url);
    }
    
    private void position () {
        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(imageLabel)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(versionLabel)
                            .addComponent(vendorLabel)
                            .addComponent(homepageLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(appVersionLabel)
                            .addComponent(appVendorLabel)
                            .addComponent(appHomepageLabel)))
                    .addComponent(appTitleLabel, GroupLayout.Alignment.LEADING)
                    .addComponent(appDescLabel, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE)
                    .addComponent(closeButton))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addComponent(imageLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(appTitleLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(appDescLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(versionLabel)
                    .addComponent(appVersionLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(vendorLabel)
                    .addComponent(appVendorLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(homepageLabel)
                    .addComponent(appHomepageLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                .addComponent(closeButton)
                .addContainerGap())
        );

        pack();
    }


}
